﻿using DuBaiCoffee2.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;

namespace DuBaiCoffee2
{
    public class DY
    {
        private static DY instance;
        private DY() { }

        public static DY Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new DY();
                }
                return instance;
            }
        }
        public void DyCS(string path)
        {
            try
            {
                using (var cvt = new JmPrint.Converter(JmPrint.PrinterType.Color, "revert=0:duplex=120"))
                {
                    var imgPath = path;
                    //cvt.ConvertImage(imgPath, 180, 180);
                    //cvt.ConvertImage(imgPath, 720, 720);
                    cvt.ConvertImage(imgPath, 600, 600);
                    var data = cvt.GetData();
                    using (var usbmgr = new USB.Manager())
                    {
                        var dd = usbmgr.Open(0);
                        var dd2 = usbmgr.Write(data);
                        usbmgr.Close();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
    }
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public static bool isMake = true;
        public static double MakingTypes = 0;
        public static string img_path = "";
        public static string IPorPortUrl = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"IPorPortMessage.txt";
        /// <summary>
        /// M12警告
        /// </summary>
        public static string WarnPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"Warn";
        /// <summary>
        /// M12故障
        /// </summary>
        public static string BreakPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"BreakDowm";
        public static double SugarInit1 = 3;
        public static double SugarInit2 = 3;
        public static double SugarInit3 = 3;
        public static bool IsStartMakingL = false;
        public static bool IsStartMakingR = false;
        public static DeviceOrderQueue list = new DeviceOrderQueue();
        public static string coffeeNameCode = "";
        public static string Img = "";
        public static int TypeL = -1;
        public MainWindow()
        {
            InitializeComponent();
        }
        public static string EmailError()
        {
            try
            {
                string msg = "<style>table{ border: 1px solid black; border-collapse: collapse; }table td{border: 1px solid #000000; padding: 5px 15px;font-size:14px;}</style><table>";
                if (WuLiaoCoffeeSel.Instance.CoffeeBean_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>CoffeeBean</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>CoffeeBean</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                if (!WuLiaoCoffeeSel.Instance.Milk_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>Milk</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>Milk</td><td>adequate materials</td></tr>";
                if (WuLiaoCoffeeSel.Instance.CupFeed1_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>Cup1</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>Cup1</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                if (WuLiaoCoffeeSel.Instance.CupFeed2_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>Cup2</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>Cup2</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                if (WuLiaoCoffeeSel.Instance.YBJ_Water)
                    msg += "<tr><td style='font-weight:bold;'>Water</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>Water</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                if (WuLiaoCoffeeSel.Instance.GT1_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>sugar1</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>sugar1</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                if (WuLiaoCoffeeSel.Instance.GT2_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>sugar2</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>sugar2</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                if (WuLiaoCoffeeSel.Instance.GT3_Sel_Bol)
                    msg += "<tr><td style='font-weight:bold;'>sugar3</td><td>adequate materials</td></tr>";
                else
                    msg += "<tr><td style='font-weight:bold;'>sugar3</td><td style='color:#FF0000;'>Lack of material</td></tr>";
                //if (!IsMsgError)
                //    msg += "<tr><td style='font-weight:bold;'>Coffee Maker</td><td>Ready</td></tr>";
                //else
                //    msg += "<tr><td style='font-weight:bold;'>Coffee Maker</td><td style='color:#FF0000;'>NotReady</td></tr>";
                msg += "</table>";
                return msg;
            }
            catch (Exception)
            {
                return "";
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!File.Exists(IPorPortUrl))
                {
                    using (FileStream stream = File.Create(IPorPortUrl))
                    {
                        stream.Close();
                        stream.Dispose();
                        IPorPortInfo porPortInfo1 = IPorPortInfo.Instance;
                        File.WriteAllText(IPorPortUrl, JsonConvert.SerializeObject(porPortInfo1));
                    }
                }
                else
                {
                    var dd = File.ReadAllText(IPorPortUrl);
                    var porPortInfo = JsonConvert.DeserializeObject<IPorPortInfo>(File.ReadAllText(IPorPortUrl));
                    IPorPortInfo.Instance.CoffeeIP = porPortInfo.CoffeeIP;
                    IPorPortInfo.Instance.CoffeePort = porPortInfo.CoffeePort;
                    IPorPortInfo.Instance.RobotIPLeft = porPortInfo.RobotIPLeft;
                    IPorPortInfo.Instance.RobotIPRight = porPortInfo.RobotIPRight;
                    IPorPortInfo.Instance.PortName = porPortInfo.PortName;
                    IPorPortInfo.Instance.PrinterCoffeeIP = porPortInfo.PrinterCoffeeIP;
                    IPorPortInfo.Instance.PrinterCofferPort = porPortInfo.PrinterCofferPort;
                    IPorPortInfo.Instance.EWMPortName = porPortInfo.EWMPortName;
                    IPorPortInfo.Instance.ZBPortName = porPortInfo.ZBPortName;
                    IPorPortInfo.Instance.CoffeePortName = porPortInfo.CoffeePortName;
                    IPorPortInfo.Instance.SugarInit1 = porPortInfo.SugarInit1;
                    IPorPortInfo.Instance.SugarInit2 = porPortInfo.SugarInit2;
                    IPorPortInfo.Instance.SugarInit3 = porPortInfo.SugarInit3;
                    MainWindow.SugarInit1 = porPortInfo.SugarInit1;
                    MainWindow.SugarInit2 = porPortInfo.SugarInit2;
                    MainWindow.SugarInit3 = porPortInfo.SugarInit3;
                    WuLiaoCoffeeSel.Instance.SugarInit1 = porPortInfo.SugarInit1;
                    WuLiaoCoffeeSel.Instance.SugarInit2 = porPortInfo.SugarInit2;
                    WuLiaoCoffeeSel.Instance.SugarInit3 = porPortInfo.SugarInit3;
                }
                if (!Directory.Exists(WarnPath))
                {
                    Directory.CreateDirectory(WarnPath);
                }
                if (!Directory.Exists(WarnPath + @"\" + DateTime.Now.ToString("yyyy")))
                {
                    Directory.CreateDirectory(WarnPath + @"\" + DateTime.Now.ToString("yyyy"));
                }
                if (!Directory.Exists(WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM")))
                {
                    Directory.CreateDirectory(WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM"));
                }
                if (!Directory.Exists(WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd")))
                {
                    Directory.CreateDirectory(WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd"));
                }
                WarnPath = WarnPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd");
                if (!Directory.Exists(BreakPath))
                {
                    Directory.CreateDirectory(BreakPath);
                }
                if (!Directory.Exists(BreakPath + @"\" + DateTime.Now.ToString("yyyy")))
                {
                    Directory.CreateDirectory(BreakPath + @"\" + DateTime.Now.ToString("yyyy"));
                }
                if (!Directory.Exists(BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM")))
                {
                    Directory.CreateDirectory(BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM"));
                }
                if (!Directory.Exists(BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd")))
                {
                    Directory.CreateDirectory(BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd"));
                }
                BreakPath = BreakPath + @"\" + DateTime.Now.ToString("yyyy") + @"\" + DateTime.Now.ToString("MM") + @"\" + DateTime.Now.ToString("dd");

                Thread thr3 = new Thread(SocketClients.Instance.socketclient);
                thr3.IsBackground = true;
                thr3.Start();
                CoffeeErversysMsg.Instance.Makelist();
                Thread thr = new Thread(IOMsg.Instance.IOSerial_Thr);
                thr.IsBackground = true;
                thr.Start();
                Thread thr4 = new Thread(EWMMsg.Instance.IOSerial_Thr);
                thr4.IsBackground = true;
                thr4.Start();
                Thread thr5 = new Thread(PwebSockets.Instance.Printer_Thr);
                thr5.IsBackground = true;
                thr5.Start();
                Thread thr6 = new Thread(IceMakingMsg.Instance.IOSerial_Thr);
                thr6.IsBackground = true;
                thr6.Start();
                Thread thr2 = new Thread(MessageShow);
                thr2.IsBackground = true;
                thr2.Start();
                Thread thr7 = new Thread(SocketClients.Instance.ClientL);
                thr7.IsBackground = true;
                thr7.Start();
                Thread thr8 = new Thread(SocketClients.Instance.ClientR);
                thr8.IsBackground = true;
                thr8.Start();
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 全部订单查询
        /// </summary>
        public static void MessageShow()
        {
            while (true)
            {
                try
                {
                    Device device = new Device();
                    string lists = JsonConvert.SerializeObject(device);
                    var data = HttpMsg.Instance.deviceOrderQueueListMsg(lists);

                    if (data != null)
                    {
                        if (isMake)
                        {
                            var msglist = JsonConvert.DeserializeObject<HTTPMsg>(data);
                            if (msglist != null)
                            {
                                if (msglist.data.ToString().Length > 10)
                                {
                                    var list = JsonConvert.DeserializeObject<List<deviceOrderQueueList>>(msglist.data.ToString());
                                    if (list.Count > 0)
                                    {
                                        if (isMake)
                                        {
                                            if (list.Count > 0)
                                            {
                                                var ddd = list.FirstOrDefault(a => a.typeList3.Count > 0);
                                                if (ddd == null) continue;
                                                if (ddd.typeList3.Count > 0)
                                                {
                                                    var make = ddd.typeList3.FirstOrDefault(a => a.status == "3" || a.status == "4");
                                                    if (make != null)
                                                    {
                                                        if (make.jsonCodeVal.Length > 4)
                                                        {
                                                            var coffeecode = JsonConvert.DeserializeObject<List<specification>>(make.jsonCodeVal);
                                                            if (coffeecode.Count > 0)
                                                            {
                                                                var coffeeID = coffeecode.FirstOrDefault(a => a.classCode != "");
                                                                if (coffeeID != null)
                                                                {
                                                                    RobotOperate.CX_Start();
                                                                    Console.WriteLine(DateTime.Now.ToString() + "  cx5");
                                                                    if (RobotOperate.pstatus == JKTYPE.ProgramState.PROGRAM_RUNNING)
                                                                    {
                                                                        if (IsStartMakingL && IsStartMakingR)
                                                                            CoffeeMaking(coffeeID.classCode, make, ddd.orderNum);
                                                                        /// CoffeeMaking("5103", null, "5103");
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }
                    }
                    Thread.Sleep(1000);
                }
                catch (Exception)
                {
                    //return;
                    Thread.Sleep(1000);
                }
            }

        }
        #region zuobi
        //public void ClientL()
        //{
        //    try
        //    {
        //        while (true)
        //        {
        //            try
        //            {
        //                if (IsStartMakingL)
        //                {
        //                    IsStartMakingL = false;
        //                    IOMsg.Instance.AllBol = false;
        //                    IOMsg.Instance.RobotBol = false;
        //                    Thread.Sleep(100);
        //                    IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_DYD);
        //                    Thread.Sleep(100);
        //                    if (IOMsg.Instance.RobotBol)
        //                    {
        //                        IOMsg.Instance.QK();
        //                    }
        //                    int code = int.TryParse(makecoffeeName, out int a) ? a : 5001;
        //                    int codeMid = code / 100;
        //                    Thread.Sleep(200);
        //                    if (codeMid == 50)//直接饮品
        //                    {
        //                        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_KFJ_UP);
        //                    }
        //                    else if (codeMid == 51)//打印品
        //                    {
        //                        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_DY_UP);
        //                    }
        //                    else if (codeMid == 52)//加冰品
        //                    {
        //                        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_JBR_UP);
        //                    }
        //                    else if (codeMid == 53)//拉花品
        //                    {
        //                        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_LHR_UP);
        //                    }
        //                    QBMsg();
        //                    Thread.Sleep(200);
        //                    IOMsg.Instance.AllBol = true;
        //                    Thread.Sleep(200);
        //                    while (true)
        //                    {
        //                        if (WuLiaoCoffeeSel.Instance.TakeCup_Sel_Bol)
        //                        {
        //                            IOMsg.Instance.AllBol = false;
        //                            Thread.Sleep(200);
        //                            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_JBCG_UP);
        //                            Thread.Sleep(200);
        //                            if (codeMid == 50)
        //                            {

        //                            }
        //                        }
        //                        else
        //                        {
        //                            IOMsg.Instance.AllBol = false;
        //                            Thread.Sleep(200);
        //                            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_WBTZ_UP);
        //                            Thread.Sleep(200);
        //                            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_DJBD_Down);
        //                            Thread.Sleep(200);
        //                            IOMsg.Instance.AllBol = true;
        //                            Thread.Sleep(200);
        //                            QBMsg();
        //                            IOMsg.Instance.AllBol = true;
        //                            Thread.Sleep(200);
        //                        }
        //                    }
        //                }
        //            }
        //            catch (Exception)
        //            {
        //            }

        //            Thread.Sleep(1000);
        //        }
        //    }
        //    catch (Exception)
        //    {
        //    }
        //}
        #endregion
        public void ClientR()
        {
            try
            {
                while (true)
                {
                    if (IsStartMakingR)
                    {
                        IsStartMakingR = false;

                    }
                    Thread.Sleep(1000);
                }

            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// 取杯
        /// </summary>
        /// <param name="cupCode"></param>
        //public static void QBMsg(int cupcode)
        //{
        //    try
        //    {
        //        IOMsg.Instance.AllBol = false;
        //        Thread.Sleep(200);
        //        if (cupcode == 2)
        //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_QJB1_UP);
        //        else
        //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_QJB2_UP);
        //        Thread.Sleep(200);
        //        while (true)
        //        {
        //            Console.WriteLine("daojiebeidian1 " + DateTime.Now.ToString());
        //            IOMsg.Instance.RobotBol = false;
        //            Thread.Sleep(200);
        //            if (cupcode == 2)
        //                IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_DDLBQ1);
        //            else
        //                IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_DDLBQ2);
        //            Thread.Sleep(200);
        //            if (IOMsg.Instance.RobotBol)
        //            {
        //                Thread.Sleep(200);
        //                IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_KFJ_Down);
        //                Thread.Sleep(200);
        //                IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_KB_Down);
        //                Thread.Sleep(200);
        //                break;
        //            }
        //        }
        //        Thread.Sleep(200);
        //        if (cupcode == 2)
        //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.Drop_Cup_start);
        //        else
        //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.Drop_Cup2_start);
        //        Thread.Sleep(500);
        //        IOMsg.Instance.AllBol = true;
        //        if (cupcode == 2)
        //        {
        //            while (WuLiaoCoffeeSel.Instance.LBQFK1_Bol) { Thread.Sleep(10); }
        //            while (!WuLiaoCoffeeSel.Instance.LBQFK1_Bol) { Thread.Sleep(10); }
        //        }
        //        else
        //        {
        //            while (WuLiaoCoffeeSel.Instance.LBQFK2_Bol) { Thread.Sleep(10); }
        //            while (!WuLiaoCoffeeSel.Instance.LBQFK2_Bol) { Thread.Sleep(10); }
        //        }
        //        IOMsg.Instance.AllBol = false;
        //        Thread.Sleep(100);
        //        if (cupcode == 2)
        //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.Drop_Cup_end);
        //        else
        //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.Drop_Cup2_end);
        //        Thread.Sleep(500);
        //        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_JCJB_UP);
        //        Thread.Sleep(500);
        //        IOMsg.Instance.RobotBol = false;
        //        while (true)
        //        {
        //            Thread.Sleep(100);
        //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_DJBJC);
        //            Thread.Sleep(100);
        //            if (IOMsg.Instance.RobotBol)
        //            {
        //                break;
        //            }
        //        }
        //        IOMsg.Instance.AllBol = true;
        //    }
        //    catch (Exception)
        //    {
        //        return;
        //    }
        //}
        //public static int CupCode(string code, int cupCode)
        //{
        //    try
        //    {
        //        int coffeecode = 5001;
        //        switch (code)
        //        {
        //            case "5001":
        //                coffeecode = 5001;
        //                break;
        //            case "5002":
        //                if (cupCode == 3)
        //                    coffeecode = 5024;
        //                else
        //                    coffeecode = 5002;
        //                break;
        //            case "5003":
        //                if (cupCode == 3)
        //                    coffeecode = 5020;
        //                else
        //                    coffeecode = 5003;
        //                break;
        //            case "5005":
        //                if (cupCode == 3)
        //                    coffeecode = 5017;
        //                else
        //                    coffeecode = 5005;
        //                break;
        //            case "5103":
        //                if (cupCode == 3)
        //                    coffeecode = 5116;
        //                else
        //                    coffeecode = 5115;
        //                break;
        //            case "5105":
        //                if (cupCode == 3)
        //                    coffeecode = 5109;
        //                else
        //                    coffeecode = 5122;
        //                break;
        //        }
        //        return coffeecode;
        //    }
        //    catch (Exception)
        //    {
        //        return 5001;
        //    }
        //}

        public static void CoffeeMakings(string makecoffeeName, DeviceOrderQueue list, string orderNum, bool CoffeeBol = true)
        {
            try
            {
                int code = int.TryParse(makecoffeeName, out int a) ? a : 5001;
                int codeMid = code / 100;

            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="makecoffeeName">50 接咖啡 51 打印 52 加冰 53 拉花</param>
        /// <param name="list"></param>
        /// <param name="orderNum"></param>
        /// <param name="CoffeeBol"></param>
        public static void CoffeeMaking(string makecoffeeName, DeviceOrderQueue list, string orderNum, bool CoffeeBol = true)
        {
            try
            {
                if (!coffeeMsg.Instance.isMaking)
                {
                    isMake = true;
                    return;
                }
                if (!WuLiaoCoffeeSel.Instance.Milk_Sel_Bol || !WuLiaoCoffeeSel.Instance.Water_Sel_Bol)//|| !WuLiaoCoffeeSel.Instance.Water_Sel_Bol || !WuLiaoCoffeeSel.Instance.CupFeed_Sel_Bol
                {
                    isMake = true;
                    return;
                }
                if (WuLiaoCoffeeSel.Instance.OutMealCup_Sel_Bol)
                {
                    CoffeeMakes.Instance.MakeMealMsg(orderNum);//出餐
                }
                isMake = false;
                int sugarCode = 0;
                int cupCode = 0;
                var msgs = JsonConvert.DeserializeObject<List<specification>>(list.jsonCodeVal);
                Console.WriteLine(DateTime.Now.ToString() + "  cx10" + list.jsonCodeVal);
                if (msgs != null)
                {
                    if (msgs.Any(a1 => a1.SugarCode != ""))
                    {
                        sugarCode = msgs.Any(a1 => a1.SugarCode == "1") ? 1 : msgs.Any(a1 => a1.SugarCode == "2") ? 2 : msgs.Any(a1 => a1.SugarCode == "3") ? 3 : 0;
                    }
                    if (msgs.Any(b => b.cupCode != ""))
                    {
                        cupCode = msgs.Any(b => b.cupCode == "1") ? 1 : msgs.Any(b => b.cupCode == "2") ? 2 : msgs.Any(b => b.cupCode == "3") ? 3 : 4;
                    }
                }
                SocketClients.Instance.ZBBS = 0;
                SocketClients.Instance.YBBS = 0;
                EditDeviceOrderStatus editDeviceOrder = new EditDeviceOrderStatus();
                editDeviceOrder.status = 4;
                editDeviceOrder.orderId = list.orderId;
                editDeviceOrder.orderGoodsId = list.id;
                var ddd = JsonConvert.SerializeObject(editDeviceOrder);
                var dd = HttpMsg.Instance.editDeviceOrderStatusMsg(ddd);
                Thread.Sleep(1000);
                ClientList clientList = new ClientList();
                clientList.MsgBol = WuLiaoCoffeeSel.Instance;
                clientList.code = 10;
                clientList.IsMake = false;
                SocketClients.Instance.client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                Img = list.lhImgPath;
                int code = int.TryParse(makecoffeeName, out int a) ? a : 6001;
                int codeMid = code / 100;
                while ((SocketClients.Instance.ZBBS == 0) || (SocketClients.Instance.YBBS == 0)) { Thread.Sleep(10); }
                if (codeMid == 63)
                {
                    while (true)
                    {
                        if (CoffeeMakeModel.Instance.IsDLHDL && CoffeeMakeModel.Instance.IsDLHDR)
                        {
                            RobotOperate.CX_Stop();
                            RobotOperate.CX_Stop_R();
                            if (RobotOperate.pstatusL == JKTYPE.ProgramState.PROGRAM_IDLE)
                            {
                                IOMsg.Instance.QK();
                                break;
                            }
                            if (RobotOperate.pstatusR == JKTYPE.ProgramState.PROGRAM_IDLE)
                            {
                                IOMsgR.Instance.QK();
                                break;
                            }
                            if (makecoffeeName == "6301")
                                RobotOperate.Robot_Move(10);
                            else if (makecoffeeName == "6302")
                                RobotOperate.Robot_Move(21);
                            RobotOperate.Robot_Yun_R();
                            RobotOperate.Robot_Yun();
                            CoffeeMakeModel.Instance.IsLHWCL = true;
                            CoffeeMakeModel.Instance.IsLHWCR = true;
                            while (!CoffeeMakeModel.Instance.IsDXBDR) { Thread.Sleep(10); }
                            while (!CoffeeMakeModel.Instance.IsDCCL) { Thread.Sleep(10); }
                            break;
                        }
                        Thread.Sleep(10);
                    }
                }
                else
                {
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(100);
                    while (true)
                    {
                        Thread.Sleep(100);
                        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.LRobot_CCWC);
                        Thread.Sleep(100);
                        if (IOMsg.Instance.RobotBol)
                        {
                            break;
                        }
                    }
                }
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(100);
                IOMsg.Instance.QK();
                IOMsgR.Instance.QK();
                Thread.Sleep(100);
                IOMsg.Instance.AllBol = true;
                SocketClients.Instance.IsClear();
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 清空左臂
        /// </summary>
        public static void QKL()
        {
            try
            {
               
            }
            catch (Exception)
            {
                return;
            }
        }
    }
}
